package cn.csg.iotplatform.module.system.dal.mysql.userzone;

import java.time.LocalDateTime;
import java.util.*;

import cn.csg.iotplatform.framework.common.pojo.PageResult;
import cn.csg.iotplatform.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.csg.iotplatform.framework.mybatis.core.mapper.BaseMapperX;
import cn.csg.iotplatform.module.system.controller.admin.permission.vo.permission.UserDeptDo;
import cn.csg.iotplatform.module.system.controller.admin.permission.vo.permission.UserDomainDo;
import cn.csg.iotplatform.module.system.controller.admin.permission.vo.permission.UserProjectDo;
import cn.csg.iotplatform.module.system.controller.admin.permission.vo.permission.UserZoneDo;
import cn.csg.iotplatform.module.system.controller.admin.user.vo.user.PageCopyUserRoleDo;
import cn.csg.iotplatform.module.system.controller.admin.user.vo.user.PageCopyUserRoleDto;
import cn.csg.iotplatform.module.system.dal.dataobject.userzone.UserZoneDO;
import org.apache.ibatis.annotations.Mapper;
import cn.csg.iotplatform.module.system.controller.admin.userzone.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * 用户分区关系 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface UserZoneMapper extends BaseMapperX<UserZoneDO> {

    default PageResult<UserZoneDO> selectPage(UserZonePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<UserZoneDO>()
                .eqIfPresent(UserZoneDO::getUserId, reqVO.getUserId())
                .eqIfPresent(UserZoneDO::getZone, reqVO.getZone())
                .betweenIfPresent(UserZoneDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(UserZoneDO::getId));
    }

    Set<String> queryUsersZones(@Param("userIds") Set<Long> userIds);

    Set<String> queryUsersDomains(@Param("userIds") Set<Long> userIds);

    Set<String> queryUsersProjects(@Param("userIds") Set<Long> sourceUserIds);

    Set<Long> queryUsersDepts(@Param("userIds") Set<Long> sourceUserIds);

    void insertUserDomainBatch(@Param("loginUserId") Long loginUserId, @Param("nowTime") LocalDateTime now, @Param("doList") List<UserDomainDo> doList);

    void deleteByUserIdAndDomains(@Param("userIds") Collection<Long> userIds, @Param("doList") Collection<String> deleteDomains);

    void insertUserZoneBatch(@Param("loginUserId") Long loginUserId, @Param("nowTime") LocalDateTime now, @Param("doList") List<UserZoneDo> doList);

    void deleteByUserIdAndZones(@Param("userIds") Set<Long> userIds, @Param("doList") Collection<String> deleteZones);

    void insertUserProjectBatch(@Param("loginUserId") Long loginUserId, @Param("nowTime") LocalDateTime now, @Param("doList") List<UserProjectDo> doList);

    void deleteByUserIdAndProjects(@Param("userIds") Set<Long> userIds, @Param("doList") Collection<String> deleteProjects);

    void insertUserDeptBatch(@Param("loginUserId") Long loginUserId, @Param("nowTime") LocalDateTime now, @Param("doList") List<UserDeptDo> doList);

    void deleteByUserIdAndDepts(@Param("userIds") Set<Long> userIds, @Param("doList") Collection<Long> deleteDepts);

    List<PageCopyUserRoleDo> queryCopyUserRoleList(@Param("dto") PageCopyUserRoleDto dto);

    Long queryCopyUserRoleTotal(@Param("dto") PageCopyUserRoleDto dto);

    List<String> getZonesByUseId(@Param("userId") Long userId);

    List<String> getDomainsByUseId(@Param("userId") Long userId);
}